package com.action;
import com.db.*;
import com.io.FileService;

import java.io.*;
public class InputAction {
	/*private DataBBSDTO dto;

	public DataBBSDTO getDto() {
		return dto;
	}

	public void setDto(DataBBSDTO dto) {
		this.dto = dto;
	}
*/
	private String name;
	private String email;
	private String homepage;
	private String subject;
	private String content;
	private File upload;
	private String pwd;
	private String uploadFileName;
	private String type;
	
	
	
	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setHomepage(String homepage) {
		this.homepage = homepage;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String insert()throws Exception
	{	
		DataBBSDTO dto=new DataBBSDTO();
		dto.setName(name);
		dto.setEmail(email);
		dto.setHomepage(homepage);
		dto.setSubject(subject);
		dto.setContent(content);
		dto.setPwd(pwd);
		dto.setRef(DataBBSManager.refMax()+1);
		if(uploadFileName==null)
		{
			dto.setFilename("");
			dto.setFilesize(0);
			dto.setFiletype("");
		}else{
			dto.setFilename(uploadFileName);
			dto.setFilesize((int)upload.length());
			dto.setFiletype(uploadFileName.substring(uploadFileName.lastIndexOf('.')+1));
			//upload
			FileService.saveFile(upload, "c:\\download", uploadFileName);
			
		}
		System.out.println("FileName1:"+upload.getName());
		System.out.println("FileName2:"+uploadFileName);
		DataBBSManager.databoardInsert(dto);
		return "success";
		
		
		
	}
	
	public String update()throws Exception
	{
		return "success";
	}
}
